package com.example.devicemanage.service.impl;

import com.example.devicemanage.dao.EquipMapper;
import com.example.devicemanage.dao.RegisterMapper;
import com.example.devicemanage.entity.Equip;
import com.example.devicemanage.entity.Regist;
import com.example.devicemanage.service.inter.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegisterServiceimp implements RegisterService {
    @Autowired
    RegisterMapper registerMapper;
    @Autowired
    EquipMapper equipMapper;


    @Override
    public List<Regist> queryAllRegist() {
        return registerMapper.queryAllRegist();
    }

    @Override
    public Regist querySingleEquip(int rid) {
        return registerMapper.querySingleRegist(rid);
    }

    @Override
    public Boolean deleteRegist(int rid) {
        return registerMapper.deleteRegist(rid) == 1 ? true : false;
    }

    @Override
    public int saveRegist(Regist regist) {
        return registerMapper.saveRegist(regist);
    }

    @Override
    public Boolean regist_intoEquip(int rid) {
        Regist regist = registerMapper.querySingleRegist(rid);
//        Equip equip=new Equip();
//        equip.setAgent(regist.getAgent());
//        equip.setCategory(regist.getCategory());
//        equip.setEname(regist.getEname());
//        equip.setManufacturer(regist.getManufacturer());
//        equip.setModel(regist.getModel());
//        equip.setNum(regist.getNum());
//        equip.setSpec(regist.getSpec());
//        equip.setSlife(regist.getSlife());
//        equip.setPrice(regist.getPrice());
//        equip.setPdate(regist.getPdate());
        equipMapper.regist_intoEquip(regist);
        registerMapper.deleteRegist(rid);
        return equipMapper.querySingle(String.valueOf(regist.getEid())) != null;
    }

    @Override
    public int updateRegist(Regist regist) {
        registerMapper.deleteRegist(regist.getRid());
        return registerMapper.updateRegist(regist);
    }
}
